﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace 配置系统集成1.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class Test1Controller : ControllerBase
    {
        private readonly IWebHostEnvironment _env;
        private readonly IConfiguration _config;
        public Test1Controller(IWebHostEnvironment env, IConfiguration config)
        {
            _env = env;
            _config = config;
        }

        [HttpGet]
        public string Demo3()
        {
            //读取环境变量的值
            return _env.EnvironmentName;
        }

        [HttpGet]
        public string Demo1()
        {
            //读取环境变量的值
            return Environment.GetEnvironmentVariable("password")!;
        }

        [HttpGet]
        public string Demo2()
        {
            //读取环境变量的值
            return Environment.GetEnvironmentVariable("Test_Env")!;
        }

        [HttpGet]
        public string Demo4()
        {
            /*
             *  vs中调试根据你launchSettings.json文件的"environmentVariables": {
             *  "ASPNETCORE_ENVIRONMENT": "Development"
             *   }的配置信息来 */

            /* 在服务器(生产环境)上默认情况下会读取appsettings.Production.json的配置文件,如果不存在
            * 配置项则读取默认appsettings.json配置文件,服务器上无需配置ASPNETCORE_ENVIRONMENT
            */
            return _config["aa"] + "," + _config["bb"];
        }


     
    }
}
